%% Codes for the article "Beliefs and Financial Crises", by Arvind Krishnamurthy and Wenhao Li.
% This file runs the calibration of the model 
% It will take a couple of days to run this file. 

%% Set Path and Add Path
clear all;
mainpath = fileparts(mfilename('fullpath'));
addpath(genpath([ mainpath, '/Codes_Model' ] ))
cd(mainpath);

%% Calibrate the Benchmark Model
model_option.model_name= 'benchmark';       
calibration_Smolayak_grid_method(model_option);  % benchmark model

%% Calibrate the Bayesian-belief Model
model_option.model_name= 'rational';            
calibration_Smolayak_grid_method(model_option);

%% Calibrate the Diagnostic-Belief Model
model_option.model_name= 'behavioral';       
calibration_Smolayak_grid_method(model_option);


%% Appendix B materials. Calibration of general belief.  ----------------------------------------
model_option.solve_model_again = false;   model_option.solve_credit_spread_again = false;  % even if we have the same solution files, resolve the model
model_option.not_adjust_eta=false;
model_option.shutoff_positions = [4, 5, 6, 7];   % Fix lambdaHL, lambdaLH, sigmaK, and eta.  The last one, eta, is adjusted later. 
model_option.model_name= 'behavioral';  
scenarios={'optimistic', 'pessimistic'};
for(round=1:3)
    for( iter = 1:length(scenarios) )
        model_option.scenario = scenarios{iter} ;   % two scenarios: optimistic and pessimistic
        calibration_Smolayak_grid_method_general_belief(model_option,round);
    end
end

